package org.lab.tracecash.guice;

import java.util.Properties;

import org.lab.tracecash.Constants;

import com.google.inject.AbstractModule;
import com.google.inject.name.Names;
import com.google.inject.persist.jpa.JpaPersistModule;

public class TracecashCoreModule extends AbstractModule {
	@Override
	public void configure() {
		Properties properties = readApplicationProperties();
		Names.bindProperties(binder(), properties);
		install(new JpaPersistModule(Constants.PERSISTENCE_UNIT_NAME));
	}

	private Properties readApplicationProperties() {
		try {
			Properties properties = new Properties();
			properties.load(getClass().getResourceAsStream(Constants.CONFIGURATION_CLASSPATH_FILE));
			return properties;
		} catch (Exception ex) {
			throw new RuntimeException("Configuration read error", ex);
		}
	}
}
